package com.ymatou.query.seller.trading.api.parameter;

import java.util.List;
import java.util.Map;

import com.ymttest.database.sqlwapper.YmtOrdersWapper;
import com.ymttest.utils.DataUtil;

/**
 * 存储过程[sp_trd_GetSellerOrderCount]
 * 
 * @author songyefeng
 *
 */
public class Sp_GetSellerOrderCount {
	private int sellerId;
	private Boolean isShangouOrder;
	private String beginTime;
	private String endTime;
	private List<Integer> orderStatus;

	public int getSellerId() {
		return sellerId;
	}

	public void setSellerId(int sellerId) {
		this.sellerId = sellerId;
	}

	public Boolean getIsShangouOrder() {
		return isShangouOrder;
	}

	public void setIsShangouOrder(Boolean isShangouOrder) {
		this.isShangouOrder = isShangouOrder;
	}

	public String getBeginTime() {
		return beginTime;
	}

	public void setBeginTime(String beginTime) {
		this.beginTime = beginTime;
	}

	public String getEndTime() {
		return endTime;
	}

	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}

	public List<Integer> getOrderStatus() {
		return orderStatus;
	}

	public void setOrderStatus(List<Integer> orderStatus) {
		this.orderStatus = orderStatus;
	}
	
	@SuppressWarnings("rawtypes")
	public List<Map> execute(){
		YmtOrdersWapper ymtOrdersWapper = new YmtOrdersWapper();
		String queryField = "o.iTradingStatus, o.bPaidInFull, COUNT(o.iOrderId) as orderCount";
		String joinCondition = null;
		StringBuffer queryCondition = new StringBuffer();
		queryCondition.append(" iBuyerId = "+sellerId);
		if(beginTime != null){
			queryCondition.append(" and dAddTime >= '"+beginTime+"'");
		}
		if(endTime != null){
			queryCondition.append(" and dAddTime <= '"+endTime+"'");
		}
		if(isShangouOrder != null){
			queryCondition.append(" and bShangouOrder = "+DataUtil.bool2Int(isShangouOrder));
		}
		if(DataUtil.isNullOrEmpty(orderStatus) == false){
			queryCondition.append(" and iTradingStatus in "+DataUtil.toInOfSql(orderStatus));
		}
		queryCondition.append(" group by iTradingStatus, bPaidInFull");
		return ymtOrdersWapper.selectOrders2(queryField, joinCondition,
				queryCondition.toString());
	}

}
